package com.vanzo.encryption;

/**
 * Created by dingo on 03/02/2018.
 */

public class Pdt {

    public static int MAX_BUFFER_LEN = 1024;

    public native String stringFromJNI();

    public static native int getGroupKey(byte[] gk, Integer iLen);
    public static native int getKillKey(byte[] gk, Integer iLen);

    public static native int systemCommand(byte[] inValue, byte[] outValue, Integer outLen);

    public static native int getSuperkey2NFC(int groupId, int terminalId, int totalTerminalSize, int firstId, byte[] gk, byte[] kk, byte[] value, Integer iLen);

    public static native int parseSuperkeyFromNFC(byte[] value, Integer iLen, Integer groupId, Integer terminalId, Integer totalTerminalSize,Integer firstId, byte[] outValue, Integer outLen);


    public static byte[] hexStringToByteArray(String s) {
        int len = s.length();
        byte[] data = new byte[len / 2];
        for (int i = 0; i < len; i += 2) {
            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                    + Character.digit(s.charAt(i + 1), 16));
        }
        return data;
    }

    public static String byteArrayToStr(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }
        String str = new String(byteArray);
        return str;
    }

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("crypdt");
        System.loadLibrary("native-lib");
    }


}
